1. Field of the Invention
The present invention relates generally to data processing systems and, more particularly, to an object-relational mapping tool that processes database views.
2. Description of the Related Art
To facilitate development of application programs that utilize relational databases, object-relational mapping tools have been developed. In general, relational databases store data in tables having rows (records) and columns (fields). The tables are usually interrelated, and thus, there is a logical structure imposed on the database. This logical structure is known as a schema. Object-relational mapping tools read a database and automatically generate source code. The source code that is generated contains a number of classes whose interrelationship reflects the logical structure, or schema, of the database. A class, such as a Java.TM. class, is a data structure containing both data members that store data and function members (or methods) that act upon the data. The source code contains one class for each table in the database, and each class has a data member for each column in the corresponding table. Additionally, the classes contain function members that are used to both get and set the values of the data members and, eventually, update the database.
By using an object-relational mapping tool, a programmer can easily generate source code to facilitate database application development. After the mapping tool generates the source code, the programmer writes code to interact with only the classes in the generated source code and not the database, thus hiding the complexities of interacting with the database from the programmer. This allows a programmer who is familiar with object-oriented programming to code against familiar classes and not unfamiliar, sometimes cumbersome to use, database query languages.
The tables contained in a database are interrelated to each other by primary and foreign keys. Each table may have a primary key, comprising one or more columns, that uniquely identifies a row in the table. Foreign keys, on the other hand, are used to associate a row in one table with one or more rows in another table. ##STR1##
For example, a business may store customer information in a database. Such a database, depicted above, may contain a Customer table and an Order table. The Customer table comprises a column for storing a customer's name and a column for storing a customer's unique identification number. The primary key for the Customer table is the customer identification column because it uniquely identifies each customer in the table and, most likely, will not change.
The Order table comprises a column for storing the purchase number, a column for storing the store where the order was placed, a column for storing the date when the order was placed, and a column for storing the customer identification number. Each time a customer places an order, a purchase order number identifies the transaction. Since purchase numbers are unique, the primary key for the Order table is defined as the purchase order column. Accordingly, each time a customer places an order, a new row will be generated containing the purchase order number, the store number, the date, and the customer's identification number. Thus a particular customer could have multiple rows in the order table, each representative of a different order transaction.
The rows in the Customer table are related to the rows in the Order table by a foreign key. The foreign key for the Order table is the customer identification column, which refers to the customer identification column in the Customer table. As such, the data contained in the two tables can be interrelated. Therefore, it is possible, via the customer identification column, to discover the customer name associated with a particular purchase order.
Tables can also have views defined on them. Views are created by query expressions and refer to a subset of one or more tables (i.e. a subset of the rows and/or columns). A view may be defined by one or more columns of the table from which the view is defined, referred to as a base table, or a view may be defined by a combination of columns from multiple base tables. In addition, a view can be nested, where the view is based on one or more previously defined views, referred to as base views.
For instance, as shown below, continuing the prior example, a view can be created containing only the purchase orders placed in 1998 or a view can be created containing only the purchase orders made from store XYZ. ##STR2##
Although beneficial to programmers, conventional object-relational mapping tools suffer from a limitation. When a programmer runs a conventional object-relational mapping tool, the mapping tool does not provide a customizable mapping of views in terms of dependency, updatability, and object mapping of views. Because of this limitation, programmers must develop additional logic in query language and low level database application programming interfaces (API's) to process the views. This makes the code development more difficult and error prone. This is both time consuming and cumbersome. In addition, because updatability and dependencies of views are not captured by conventional mapping tools, any attempt to update a subsequently created view can lead to inconsistent database state. It is therefore desirable to improve object-relational mapping tools.